Skip to content

bug: Identifiers can't be parsed cross module boundaries#1560

Closed
DarkPurple141 wants to merge 1 commit into
vega:nextfrom
DarkPurple141:minimal-repro-of-identifier-bug
Closed

bug: Identifiers can't be parsed cross module boundaries#1560
DarkPurple141 wants to merge 1 commit into
vega:nextfrom
DarkPurple141:minimal-repro-of-identifier-bug

Conversation

@DarkPurple141
Copy link
Copy Markdown

This is a minimal reproduction of existing behavior around the NodeParser throwing an UnknownNodeError for valid in scope identifiers.

eg.

// module.ts
const y = "hello";

export const x = {
    z: y,
};
// main.ts
import { x } from "./module";

type Identifier = typeof x;

export interface MyObject {
    field: Identifier;
}

Error:

Unknown node " y" of kind "Identifier"

My expectation of is that this would be able to be parsed - as this kind of type inference via an identifier is a common use case.

it("import-exposed", assertValidSchema("import-exposed", "MyObject"));
it("import-internal", assertValidSchema("import-internal", "MyObject", "basic"));
it("import-anonymous", assertValidSchema("import-anonymous", "MyObject"));
it.only("import-identifier", assertValidSchema("import-identifier", "MyObject"));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove this later

@domoritz
Copy link
Copy Markdown
Member

domoritz commented Feb 7, 2023

Thanks for the repro. This will Haley confirm the fix later.

@arthurfiorette
Copy link
Copy Markdown
Collaborator

Hey @DarkPurple141 is this still a problem?

@arthurfiorette arthurfiorette added the feedback Waiting for feedback resolution label May 16, 2025
@rockerBOO
Copy link
Copy Markdown

I merged in next branch and ran

npm run --silent run -- --path 'test/valid-data/import-identifier/main.ts' --type 'MyObject'
{
  "$ref": "#/definitions/MyObject",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "MyObject": {
      "additionalProperties": false,
      "properties": {
        "field": {
          "additionalProperties": false,
          "properties": {
            "z": {
              "const": "hello",
              "type": "string"
            }
          },
          "required": [
            "z"
          ],
          "type": "object"
        }
      },
      "required": [
        "field"
      ],
      "type": "object"
    }
  }
}

Seems to work now

The updated branch:

https://github.com/rockerBOO/ts-json-schema-generator/tree/minimal-repro-of-identifier-bug

@domoritz domoritz closed this Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug feedback Waiting for feedback resolution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants